<template>
  <div class="list" ref="wrapper">
    <div>
      <div class="area">
        <div class="title">当前城市</div>
        <div class="button-list">
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
        </div>
      </div>
      <div class="area">
        <div class="title">热门城市</div>
        <div class="button-list">
          <div class="button-wrapper" v-for="item of hot" :key="item.id">
            <div class="button">{{item.name}}</div>
          </div>

        </div>
      </div>
      <div class="area" v-for="(item, key) of cities" :key="key" :ref="key">
        <div class="title">{{key}}</div>
        <div class="item-list">
          <div class="item" v-for="innerItem of item" :key="innerItem.id">{{innerItem.name}}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Bscroll from 'better-scroll'
export default {
  name: 'CityList',
  props: {
    hot: Array,
    cities: Object,
    letter: String
  },
  watch: {
    letter () {
      if (this.letter !== '') {
        const el = this.$refs[this.letter][0]
        this.scroll.scrollToElement(el)
      }
    }
  },
  mounted () {
    this.scroll = new Bscroll(this.$refs.wrapper)
  }
}
</script>
<style lang="stylus" scoped>
@import "~styles/variables.styl"
  .list
    position: absolute
    top: 1.6rem
    left: 0
    bottom: 0
    right: 0
    overflow: hidden
.title
    font-size: .26rem
    padding: .24rem .3rem
    -webkit-font-smoothing: antialiased
    background-color: #f5f5f5
  .button-list
    overflow: hidden
    padding: .1rem .6rem .1rem .1rem
  .button-wrapper
    float: left
    width: 33.33%
    .button
      margin: .1rem
      padding: .1rem
      text-align: center
      border: .02rem solid #ddd
      border-radius: .06rem
  .item-list
    .item
      padding: .2rem
      color: #666
      border-bottom: .02rem solid #d5d5d5
</style>
